import {
	defineStore
} from 'pinia'
import {
	useMemoStore
} from '@/stores/memoStore'
import api from '@/services/api/memo'

export const location = defineStore('location', {
	state: () => ({
		latitude: '',
		longitude: ''
	}),
	actions: {		
		async locationChange(latitude, longitude) {
			this.latitude = latitude
			this.longitude = longitude
			const id = await useMemoStore().getUserId()
			try {
				console.log("location中发送的数据:", useMemoStore().id, this.latitude, this.longitude)
				const res = await api.postLocation(useMemoStore().id, this.latitude, this.longitude)
				console.log("stores/location(res):", res)
			} catch(error) {
				console.log("stores/location(error):", error)
			}
		}
	}
})